﻿
Partial Class App_Test_DownloadTweets
    Inherits MyUI.PageBaseApp

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load



        Dim tc = New WebApi.Twitter.TwitterClient(DB.TAB.Account_Auth.ToObj.getOauth)

        tc.InitStreamSearch(UI.Page.GetValue("q").Replace(".", "#"))

        Dim ct = 0

        Me.Response.BufferOutput = False
        Do
            Dim tweets = tc.GetStreamSearch()

            If tweets.StartsWith("{""created_at""") Then
                Dim t = MyApp.JSONDeserializeObj(Of WebApi.Twitter.Tweet)(tweets)

                Me.Response.Write("<li>" + t.text + "</li>")

            End If


            ct += 1

        Loop Until ct > 1000










        'Dim request As Net.HttpWebRequest = Net.WebRequest.Create("https://stream.twitter.com/1.1/statuses/sample.json")

        'Dim oAuth = CurrUser.Tab_UserAccount.ToObj.getOauth

        ''request.CookieContainer = _CookieContainer
        ''request.UserAgent = _UserAgent
        ''request.Timeout = _Timeout

        ''aggiunge gli header della oath
        'If oAuth IsNot Nothing Then
        '    oAuth.oauthMethod = request.Method
        '    oAuth.generateSignature(request)
        '    request.Headers.Add(oAuth.getAuthorizationParams())
        'End If


        'request.Accept = "*/*"
        'request.UserAgent = "OAuth gem v0.4.4"
        'request.ContentType = "application/x-www-form-urlencoded"

        'Dim response = request.GetResponse()

        'Dim r = New IO.StreamReader(response.GetResponseStream, Encoding.UTF8)

        'Me.Response.BufferOutput = False

        'Dim ct = 0
        'Do
        '    Dim d = r.ReadLine


        '    Me.Response.Write("<li>" + d + "</li>")

        '    ct += 1

        'Loop Until ct > 100


    End Sub
End Class
